<template>
  <edu-input :value.sync="current_field" :args="current_args" />
</template>

<script>
import EduInput from '@public/form/input';
export default {
  components: {
    EduInput
  },
  props: {
    value: {
      type: String,
      default: ''
    },
    args: {
      type: Object,
      default: () => {
        return {};
      }
    },
    formDatas: {
      type: Object,
      required: true,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      current_field: this.value,
      current_args: {
        ...this.args,
        disabled: (this.formDatas.course_data_type == 3 || this.formDatas.course_data_type == 4) ? 1 : 0
      }
    };
  },
  watch: {
    current_field(value) {
      this.$emit('update:value', value);
    },
    value: {
      handler(now, old) {
        this.current_field = now;
      }
    },
    'formDatas.course_data_type': {
      handler(now, old) {
        const isDisabled = this.formDatas.course_data_type == 3 || this.formDatas.course_data_type == 4;
        this.$set(this.current_args, 'disabled', isDisabled ? 1 : 0);
        this.$emit('update:value', 0);
      }
    }
  }
};
</script>

<style></style>
